<template>
	<div>
		<common-info-dialog :title="dialogTitle" is-fixed-height :visible.sync="dialogShow" @cancel="dialogShow=false"  >
      <common-list>
<!--      <common-edit-dialog-->
<!--        :title="dialogTitle"-->
<!--        :visible.sync="dialogShow"-->
<!--        @cancel="close"-->
<!--        @submit="submitForm"-->
<!--        :button-loading="isPersistenceLoading"-->
<!--      >-->
			<!-- 按钮组织start -->
			<el-row slot="search" :gutter="10" class="mb8">
				<el-col :span="1.5">
					<el-button type="danger" plain icon="el-icon-delete" :disabled="multiple" @click="del(selectionIds)">批量删除</el-button>
				</el-col>
			</el-row>
			<!-- 头部搜素end -->
			<common-table slot="content" v-loading="loading" :data="list" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" align="center"  />
				<el-table-column label="用户名" align="left" prop="userCode">
					<template slot-scope="{row}">{{ row.userCode?row.userCode:'-' }}</template>
				</el-table-column>

				<!-- <el-table-column label="访问策略名称" align="left" prop="ruleName">
					<template slot-scope="{row}">{{ row.ruleName }}</template>
				</el-table-column>-->

				<el-table-column label="IP地址" align="left" prop="ipAddress">
					<template slot-scope="{row}">{{ row.ipAddress }}</template>
				</el-table-column>

				<el-table-column label="操作"  align="left" width="160">
					<template slot-scope="{row}">
						<el-button type="text" @click="edit(row)">编辑</el-button>
						<el-button type="text" @click="del([row.userVisitRuleId])">删除</el-button>
					</template>
				</el-table-column>
			</common-table>
			<pagination slot="pagination"  v-show="total>0" :total="total" :page.sync="query.pageNum" :limit.sync="query.pageSize" @pagination="getList" />
      </common-list>
		</common-info-dialog>
		<!-- 列表 end -->
		<editDialog ref="editDialog" @refresh="getList" />

	</div>
</template>

<script>
import {
	visitsourcerule_queryPageList,
	visitsourcerule_deleteUserVisitRule,
} from '@/api/management/configure/index.js';
import editDialog from '../components/fromDialog';
export default {
	components: { editDialog },
	props: {},
	data() {
		return {
			dialogShow: false,
			dialogTitle: '编辑访问来源策略',
			total: 1, // 总条数
			loading: false, // table 加载中
			list: [], // 数据列
			selectionIds: '', // 列表选中数据id
			single: true, // 非单个禁用
			multiple: true, // 非多个禁用
			query: {
				pageNum: 1,
				pageSize: 10,
			}, // 查询条件
		};
	},
	watch: {},
	computed: {},
	methods: {

		/**
		 * 选择
		 */
		handleSelectionChange(selection) {
			this.selectionIds = selection.map((item) => item.userVisitRuleId);
			this.single = selection.length != 1;
			this.multiple = !selection.length;
		},
		/**
		 * 显示
		 */
		show(userId) {
			this.dialogShow = true;
			this.query.userId = userId;
			this.handleQuery();
			//this.form = data.id ? data : this.$options.data().form;
		},
		/**
		 * 查询
		 */
		handleQuery() {
			this.query.pageNum = 1;
			this.getList();
		},
		/**
		 * 重置查询
		 */
		resetQuery() {
			this.query = this.$options.data().query;
		},
		/**
		 * 获取列表
		 */
		getList() {
			let query = { ...this.query };
			this.loading = true;
			visitsourcerule_queryPageList(query).then((res) => {
				this.list = res.rows;
				this.total = res.total;
				this.loading = false;
			});

		},
		/**
		 * 新增/编辑
		 */
		edit(row) {
			this.$refs.editDialog.show(row ? { ...row } : {});
		},
		/**
		 * 删除
		 */
		del(ids) {
			this.$GlobalDeleteConfirm('是否确认删除数据项?', '警告', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
			})
				.then(() => {
					visitsourcerule_deleteUserVisitRule({
						ids: ids.join(','),
					}).then((res) => {
						this.getList();
						this.$GlobalSuccessMessage('删除成功');
					});
				}).catch(()=>{});
		},
	},
	created() {
		this.getList();
	},
	mounted() {},
};
</script>
<style lang="scss">
</style>
